<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/user_php.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
	<title>Studial</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" type="text/css" href="../css/global.css" />
<link rel="stylesheet" type="text/css" href="../css/users.css" />
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
	.postcontainer {
		margin: 2em auto 2em 0;
		width: 700px;
		border-top: 1pt solid #d0d0d0;
	}
	
	.blueblock {
		margin: 2px 0 2px 0;
		background-color: #B8D7B4;	
	}
	
	.leftavatar {
		float: left;
		width: 50px;
		margin-top: 1.5em;
	}
	
	.leftavatar img { width: inherit; }
	
	.topiccol {
		float: right;
		width: 630px;
		padding-left: 20px;
	}
</style>
<!-- InstanceEndEditable -->
</head>

<body>
	<div class="header">
        <div class="innercontent">
            <img alt="Studial" class="logo" src="../images/logo.jpg" />   
            <form id="searchform" method="post" action="">
                <div id="searchblock">
                    <input id="searchfield" name="searchfield" type="text" placeholder="Tìm kiếm" />
                    <button id="searchbutton" type="submit" name="search" value="1" title="Tìm kiếm" onclick="window.location = '../unlogged/index.php'"><img id="searchicon" src="../images/searchicon.png" /></button>
                </div>           
            </form>
            <div id="rightheader">
                <a class="headerbutton" id="logout"><span id="borderleft"></span>Đăng xuất</a>
                <a class="headerbutton" id="toboard"><?php echo "Username" ?></a>
            </div>
        </div>
    </div>
    <div class="innercontent">
        <div id="leftcolumn">
            <img alt="Avatar" id="largeavatar" src="<?php echo $path = "../images/male_avatar.png"; ?>" />
        	<div id="sidenavcontainer">	
                <ul id="sidenav">
            		<li><a class="navlink" href=""><span id="boardnav">Bảng</span></a></li>
                    <li><a class="navlink" href=""><span id="infonav">Thông tin</span></a></li>
                    <li><a class="navlink" href=""><span id="friendnav">Bạn bè</span></a></li>
                    <li><a class="navlink" href=""><span id="phovidnav">Phim ảnh</span></a></li>
                    <li><a class="navlink" href=""><span id="coursenav">Khóa học</span></a></li>
            	</ul>
            </div>
        </div>
        <div id="contentcolumn">
        	<div id="contentcolheader">
            	<h1>Username</h1>
            </div>
		<!-- InstanceBeginEditable name="maincontent" -->
        <?php
			$username = $_COOKIE['studialusername'];
			$password = $_COOKIE['studialuserpwd'];
			$userid = $_COOKIE['studialuserid'];
			
			@ $db = mysql_pconnect("localhost","root","");
			
			if(!$db)
			{
				echo "<h2>Database does not exist!</h2>";
				exit;
			}
			
			mysql_set_charset('UTF8');
			mysql_select_db('Studial');
			
			$selectUser = "SELECT * FROM `users` WHERE username = '".$username."'";
			$resultUser = mysql_query($selectUser);
			$rowUser = mysql_fetch_array($resultUser);
			
			$selectTopics = "SELECT * FROM `topics` WHERE home_id = '".$userid."' type = 1";
			$resultTopics = mysql_query($selectTopics);
			$rowTopics = mysql_fetch_array($resultTopics);
			$numTopicsResult = mysql_num_rows($resultTopics );
			
			$selectComments = "SELECT * FROM `comments`";
			$resultComments = mysql_query($selectComments);
			$rowComments = mysql_fetch_array($resultComments);
			$numCommentsResult = mysql_num_rows($resultComments);
		?>
			<form id="topicform" name="topicform" method="post" action="../postHandler.php">
            	<input name="userid" type="hidden" value="" />
                <input name="homeid" type="hidden" value="" />
                <textarea name="comment" placeholder="Chủ đề" title="Viết chủ đề"></textarea>
                <input name="link" placeholder="Liên kết" title="Điền liên kết" />
                <button class="greenbutton" type="submit" name="submit" value="1" title="Đăng chủ đề">Đăng</button>
            </form>
            <div class="postcontainer">
            	<div class="leftavatar">
                	<img alt="Ava" src="../images/male_avatar.png" />
                </div>
                <div class="topiccol">
					<?php
                        for($i=1; $i<=$numTopicsResult; $i++)
                        {
                            echo '<div class="topicblock">';
                            echo '	<div class="topicusername">';
							echo 		stripslashes($rowUser['lastname'])." ".stripslashes($rowUser['firstname']); 
                            echo '	</div>';
                            echo '	<div class="topiccontent">';
							echo 		stripslashes($rowTopics['content']);  
                            echo '	</div>';
                            echo '	<div class="topiclink">';
							echo '		<a href="'.stripslashes($rowTopics['link']).'"></a>';
                            echo '	</div>';
                            echo '	<div class="topicinfo">';
							echo 		stripslashes($rowTopics['datecreated']).' - '; 
                            echo '	</div>';
                            echo '		<span class="topiclike" id="topicid">';
							echo '			<a href="../topicHandlerLike.php?UserID="'.$userid.'>Thích</a>';
                            echo ' 		</span>';
                            echo '	</div>';
                            echo '</div>';
                            echo '<div class="topicrefblock">';
                            echo '	<div class="blueblock"><img alt="Like" src="../images/likeicon.png" />';
							echo 		stripslashes($rowTopics['numliked']).' người thích'; 
                            echo '	</div>';
                            echo '	<div class="blueblock">';
							echo 		stripslashes($rowTopics['numcommented']).' bình luận'; 
                            echo '	</div>';
							echo '	<div class="commentcontainer">';
							for($i=1; $i<=$numCommentsResult; $i++)
							{
								echo '		<div class="blueblock">';
								echo '			<span class="commentusername">';
								echo 				stripslashes($rowUser['firstname'])." ".stripslashes($rowUser['lastname']); 
								echo '			</span>';
								echo '			<span class="commentcontent">';
								echo 				stripslashes($rowComments['content']);
								echo '			</span>';
								echo '			<span class="commentlink">';
								echo '				<a href="'.stripslashes($rowComments['link']).'"></a>';
								echo '			</span>';
								echo '			<div class="commentinfo">';
								echo 				stripslashes($rowComments['datecommented']); 
								echo '				<span class="commentlike" id="commentid">';
								echo '					<a href="../commentHandlerLike.php?UserID="'.$userid.'>Thích</a>';
								echo '				</span>';
								echo '			</div>';
								echo '		</div>';
							}
							echo '	</div>';
                            echo '	<div class="blueblock">';
                            echo '		<form class="commentform" name="commentform" method="post" action="../commentHandler.php">';
                            echo '			<input name="userid" type="hidden" value="" />';
                            echo '			<input name="topicid" type="hidden" value="" />';
                            echo '			<textarea name="comment" placeholder="Bình luận" title="Viết bình luận"></textarea>';
                            echo '			<input name="link" placeholder="Liên kết" title="Điền liên kết" />';
                            echo '			<button class="greenbutton" type="submit" name="submit" value="1" title="Đăng bình luận">Đăng</button>';
                            echo '		</form>';
                            echo '	</div>';
                            echo '</div>';
                        }
                    ?>
                </div>
            </div>	
		<!-- InstanceEndEditable -->
    	</div>
    </div>
    <div class="footer">
    	<div id="leftfooter">Studial @ 2012 - Nhóm 01</div>
        <div id="rightfooter">
			<a href="" title="Đăng ký thêm tên trường vào hệ thống">Đăng ký trường</a>
            -
            <a href="" title="Đăng ký thêm tên ngành học vào hệ thống">Đăng ký ngành</a>
        </div>
    </div>       
</div>
</body>
<!-- InstanceEnd --></html>
